import type { AddressItem, AddressParams } from '@/types/address'
import { http } from '@/utils/http'
/**
 * 添加或者修改收货地址
 * @param id 修改需要携带的id
 * @param data 请求参数
 */
export const postOrPutMemberAddressAPI = (data: AddressParams, id?: string) => {
  if (id) {
    return http({
      method: 'PUT',
      url: `/member/address/${id}`,
      data,
    })
  } else {
    return http({
      method: 'POST',
      url: '/member/address',
      data,
    })
  }
}
/**
 * 获取地址列表
 *
 */
export const getMemberAddressAPI = (id?: string) => {
  if (id) {
    return http<AddressItem>({
      method: 'GET',
      url: `/member/address/${id}`,
    })
  } else {
    return http<AddressItem[]>({
      method: 'GET',
      url: '/member/address',
    })
  }
}
/**
 * 删除地址列表
 * @param id 地址id(路径参数)
 */
export const deleteMemberAddressByIdAPI = (id: string) => {
  return http({
    method: 'DELETE',
    url: `/member/address/${id}`,
  })
}
